package cn.com.joycode.nimble.opencv.test.douyin.svga;

import cn.com.joycode.nimble.opencv.test.BaseTest;
import lombok.extern.slf4j.Slf4j;
import org.bytedeco.opencv.global.opencv_core;
import org.bytedeco.opencv.global.opencv_imgproc;
import org.bytedeco.opencv.opencv_core.Mat;
import org.bytedeco.opencv.opencv_core.MatVector;
import org.bytedeco.opencv.opencv_core.Scalar;
import org.junit.jupiter.api.Test;

@Slf4j
public class DouyinLiveCastTag extends BaseTest {

    @Test
    public void inRangeTest() {
        String resourcePath = "images/douyin/samples/540/0002.png";
        Mat mat1 = readResource(resourcePath);
        Mat bg = new Mat().put(mat1);
        Mat mat2 = new Mat();
        opencv_imgproc.cvtColor(mat1, mat2, opencv_imgproc.CV_BGR2HSV);
        Mat mask = new Mat();
        // 绿色
        Mat low = new Mat(new Scalar(35, 43, 46, 0));
        Mat high = new Mat(new Scalar(77, 255, 220, 0));
        // 红色
        low = new Mat(new Scalar(0, 43, 46, 0));
        high = new Mat(new Scalar(10, 255, 255, 0));
        opencv_core.inRange(mat2, low, high, mask);
        Mat r = new Mat();
        r.put(mask);
        low = new Mat(new Scalar(156, 0, 100, 0));
        high = new Mat(new Scalar(180, 255, 255, 0));
        opencv_core.inRange(mat2, low, high, mask);
        opencv_core.bitwise_or(r, mask, r);
        mask.put(r);
        log.info("mask type:{}", mask.type());
        Mat m = new Mat();
        mat1.copyTo(m, mask);
        Mat result = new Mat();
        opencv_imgproc.cvtColor(mask, mask, opencv_imgproc.CV_GRAY2BGR);
        MatVector mv = new MatVector();
        mv.put(mat1, m, mask);
        opencv_core.hconcat(mv, result);
        show(result);
    }
}
